package org.kealinghornets.jchuah.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Toast;


public class MyActivity2 extends Activity {



    int numCleared = 0;


    public void onClockButtonPush (final View viewMyView){








        Animation fade_out_animation = AnimationUtils.loadAnimation(this, R.anim.fade_out);
        fade_out_animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                viewMyView.setEnabled(false);
                numCleared = numCleared + 1;


            }

            @Override
            public void onAnimationEnd(Animation animation) {
                numCleared = numCleared - 1;
                viewMyView.setEnabled(true);



                viewMyView.clearAnimation();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        Animation fade_in_animation = AnimationUtils.loadAnimation(this, R.anim.fade_in);
        fade_in_animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                viewMyView.setAlpha(1);
                viewMyView.setEnabled(false);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                viewMyView.setEnabled(true);
                viewMyView.setAlpha(1);
                viewMyView.clearAnimation();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        if (viewMyView.getAlpha()==1) {
            viewMyView.startAnimation(fade_out_animation);



        }else{
            viewMyView.setAlpha(1);



        }

        String clockName = getResources().getResourceEntryName(viewMyView.getId());
        int clockRow = Integer.parseInt(clockName.charAt(5) + "");
        int clockColumn = Integer.parseInt(clockName.charAt(6)+ "");
        Log.d("clock", "row: " + clockRow + "column: "+ clockColumn);

        int getRow = 0;
        int getColumn = 0;
        View otherClock = ((View)viewMyView.getParent()).findViewById(getResources().getIdentifier("clock" + getRow + getColumn, "id", getPackageName()));


        if (numCleared == 39) {
            Log.d("all cleared", "win" + System.currentTimeMillis());
            Toast.makeText(this, "You Win! YAY!", Toast.LENGTH_LONG).show();




        }
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_activity2);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my_activity2, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
